/**
 * Created by kevin on 17/8/4.
 */
var Router = require('koa-router')
var Docker = require('dockerode')
var path = require('path')
var tar = require('tar-fs')

function register(app) {
    var router = new Router({
        prefix: '/docker'
    });

    router.get('/', function *(next) {
        var docker = new Docker({socketPath: '/var/run/docker.sock'});
        // docker.listContainers(function (err, containers) {
        //     containers.forEach(function (containerInfo) {
        //         console.log(containerInfo)
        //         // docker.getContainer(containerInfo.Id).stop(cb);
        //     });
        // });


        var centos7_path = path.resolve(__dirname, '../../../dockerfiles/centos7');
        var tarStream = tar.pack(centos7_path)
        console.log(process.cwd(), ' - - -- - - - --- - - - -', centos7_path)

        docker.buildImage(
            tarStream, {t: 'shuimin/centos7_node'}, function(err, response) {
            console.log('asdlololo')
            console.log('lololo')
        });

        this.body = 'lalala'
    });


    app.use(router.routes());
    app.use(router.allowedMethods());
}

module.exports = register;